package com.hatic.money;

import java.util.Map;

import org.jxstar.dao.DaoParam;
import org.jxstar.service.BusinessObject;

/**
 * 数据维护功能。
 *
 * @author TonyTan
 * @version 1.0, 2011-11-9
 */
public class PlanModifyBO extends BusinessObject {
	private static final long serialVersionUID = 1L;

	public String delsub(String[] planIds) {
		if (planIds == null || planIds.length == 0) {
			setMessage("没有选择子投资计划！");
			return _returnFaild;
		}
		
		String parentId = getParentId(planIds[0]);
		_log.showDebug(".....................parentId=" + parentId);
		
		//更新子投资计划状态为正常投资计划
		String usql = "update money_plan set bao_type = '0', up_comp = '0', " +
				"plan_parentid = '', plan_parentcode = '' where plan_id = ?";
		DaoParam uparam = _dao.createParam(usql);
		for (int i = 0; i < planIds.length; i++) {
			uparam.addStringValue(planIds[i]);
			_dao.update(uparam);
			
			uparam.clearParam();
		}
		
		//重新计算计划包的合计金额
		(new PlanMemoBO()).updateSum(parentId);
		
		return _returnSuccess;
	}
	
	//取子投资计划的父ID
	private String getParentId(String planId) {
		String sql = "select plan_parentid from money_plan where plan_id = ?";
		DaoParam param = _dao.createParam(sql);
		param.addStringValue(planId);
		
		Map<String, String> mpData = _dao.queryMap(param);
		return mpData.get("plan_parentid");
	}
}
